<?php
include("session.php");
include("config.php");
$loc_entity = RLang("task");
$row = prepare_edit(LEVEL_EDIT_TASK, LEVEL_CREATE_TASK, "edit_task.php", $loc_entity, "task", $db, "maintime.php");
if (!$row)
   exit();

$projectIsRetired = false;
$customerIsRetired = false;
if ($row != 0) {
   $sql = "SELECT * FROM project where id = ?";
   if (!$result = get_db_result($db, $sql, "i", $row['project_id'])) {
      echo ($sql . " ");
      die(mysqli_error($db));
   }
   $prow = mysqli_fetch_array($result, MYSQLI_ASSOC);
   $projectIsRetired = $prow['retired'] != null;

   $sql = "SELECT * FROM customer where id = ?";
   if (!$result = get_db_result($db, $sql, "i", $prow['customer_id'])) {
      echo ($sql . " ");
      die(mysqli_error($db));
   }
   $crow = mysqli_fetch_array($result, MYSQLI_ASSOC);
   $customerIsRetired = $crow['retired'] != null;
   $readonly = $customerIsRetired || $projectIsRetired || $row['retired'] != null;

}else
   $readonly = false;
   
$fallback = "maintime.php";

$action = "write_task.php";  
$fields = [
 ["name" => "name", "loc" => RLang("name"), "type" => "text", "limit" => 50],
 ["name" => "project_id", "loc" => RLang("project"), "type" => "selection", "sql" => "SELECT * FROM project where retired is null"],
 ["name" => "created", "loc" => RLang("created"), "type" => "text", "readonly" => true],
];
include("itable_editor.php");
?>
